﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   <head>
      <title>GPX Parser</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
      <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>

      <script type="text/javascript">
          var map;
          function GetMap() {
              // Initialize the map
              map = new Microsoft.Maps.Map(document.getElementById("myMap"), { credentials: "Your_Bing_Maps_Key" });

              //Register and load the GPX Parser Module
              Microsoft.Maps.registerModule("GPXParserModule", "scripts/GPXParserModule.js");
              Microsoft.Maps.loadModule("GPXParserModule");
          }

          function LoadGPX(url) {
              map.entities.clear();

              //Define default shape options

              var myTrackOptions = {
                  strokeColor: new Microsoft.Maps.Color(156, 0, 0, 255)
              };

              var myRouteOptions = {
                  strokeColor: new Microsoft.Maps.Color(156, 0, 0, 255)
              };

              var myPushpinOptions = {
              };

              new GPXParser().Parse(url, GPXCallback, { pushpinOptions: myPushpinOptions, routeOptions: myRouteOptions, trackOptions: myTrackOptions });
          }

          function GPXCallback(items) {
              map.entities.push(items);

              //Advance functionalities can be added here such as adding event handlers.

              //Set the map view
              if (items.Metadata != null && items.Metadata.LocationRect != null) {
                  map.setView({ bounds: items.Metadata.LocationRect });
              }              
          }
      </script>
   </head>
   <body onload="GetMap();">
        <div id='myMap' style="position:relative; width:600px; height:600px;"></div>   
       <input type="button" value="Local file (GPS Points)" onclick="LoadGPX('/Data/gps_points.xml')" />
       <input type="button" value="Local file (UK tourist locations)" onclick="LoadGPX('/Data/Tourist_locations_UK-England.xml')" />
   </body>
</html>